﻿#region Using directives

using System;
using System.Data;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;

using CBRSystem.Entities;
using CBRSystem.Data;

#endregion

namespace CBRSystem.Data.Bases
{	
	///<summary>
	/// This class is the base class for any <see cref="EnrolledStudentProviderBase"/> implementation.
	/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
	///</summary>
	public abstract partial class EnrolledStudentProviderBaseCore : EntityProviderBase<CBRSystem.Entities.EnrolledStudent, CBRSystem.Entities.EnrolledStudentKey>
	{		
		#region Get from Many To Many Relationship Functions
		#endregion	
		
		#region Delete Methods

		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="transactionManager">A <see cref="TransactionManager"/> object.</param>
		/// <param name="key">The unique identifier of the row to delete.</param>
		/// <returns>Returns true if operation suceeded.</returns>
		public override bool Delete(TransactionManager transactionManager, CBRSystem.Entities.EnrolledStudentKey key)
		{
			return Delete(transactionManager, key.EnrolledStudentId);
		}
		
		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="_enrolledStudentId">The primary key.. Primary Key.</param>
		/// <remarks>Deletes based on primary key(s).</remarks>
		/// <returns>Returns true if operation suceeded.</returns>
		public bool Delete(System.Int32 _enrolledStudentId)
		{
			return Delete(null, _enrolledStudentId);
		}
		
		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_enrolledStudentId">The primary key.. Primary Key.</param>
		/// <remarks>Deletes based on primary key(s).</remarks>
		/// <returns>Returns true if operation suceeded.</returns>
		public abstract bool Delete(TransactionManager transactionManager, System.Int32 _enrolledStudentId);		
		
		#endregion Delete Methods
		
		#region Get By Foreign Key Functions
	
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_ClassList_EnrollmentStatus key.
		///		FK_ClassList_EnrollmentStatus Description: 
		/// </summary>
		/// <param name="_currentStatus">The key for the current enrollment status of the student for this section.</param>
		/// <returns>Returns a typed collection of CBRSystem.Entities.EnrolledStudent objects.</returns>
		public TList<EnrolledStudent> GetByCurrentStatus(System.Int32 _currentStatus)
		{
			int count = -1;
			return GetByCurrentStatus(_currentStatus, 0,int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_ClassList_EnrollmentStatus key.
		///		FK_ClassList_EnrollmentStatus Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_currentStatus">The key for the current enrollment status of the student for this section.</param>
		/// <returns>Returns a typed collection of CBRSystem.Entities.EnrolledStudent objects.</returns>
		/// <remarks></remarks>
		public TList<EnrolledStudent> GetByCurrentStatus(TransactionManager transactionManager, System.Int32 _currentStatus)
		{
			int count = -1;
			return GetByCurrentStatus(transactionManager, _currentStatus, 0, int.MaxValue, out count);
		}
		
			/// <summary>
		/// 	Gets rows from the datasource based on the FK_ClassList_EnrollmentStatus key.
		///		FK_ClassList_EnrollmentStatus Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_currentStatus">The key for the current enrollment status of the student for this section.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of CBRSystem.Entities.EnrolledStudent objects.</returns>
		public TList<EnrolledStudent> GetByCurrentStatus(TransactionManager transactionManager, System.Int32 _currentStatus, int start, int pageLength)
		{
			int count = -1;
			return GetByCurrentStatus(transactionManager, _currentStatus, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_ClassList_EnrollmentStatus key.
		///		fkClassListEnrollmentStatus Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_currentStatus">The key for the current enrollment status of the student for this section.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of CBRSystem.Entities.EnrolledStudent objects.</returns>
		public TList<EnrolledStudent> GetByCurrentStatus(System.Int32 _currentStatus, int start, int pageLength)
		{
			int count =  -1;
			return GetByCurrentStatus(null, _currentStatus, start, pageLength,out count);	
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_ClassList_EnrollmentStatus key.
		///		fkClassListEnrollmentStatus Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_currentStatus">The key for the current enrollment status of the student for this section.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of CBRSystem.Entities.EnrolledStudent objects.</returns>
		public TList<EnrolledStudent> GetByCurrentStatus(System.Int32 _currentStatus, int start, int pageLength,out int count)
		{
			return GetByCurrentStatus(null, _currentStatus, start, pageLength, out count);	
		}
						
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_ClassList_EnrollmentStatus key.
		///		FK_ClassList_EnrollmentStatus Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_currentStatus">The key for the current enrollment status of the student for this section.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns a typed collection of CBRSystem.Entities.EnrolledStudent objects.</returns>
		public abstract TList<EnrolledStudent> GetByCurrentStatus(TransactionManager transactionManager, System.Int32 _currentStatus, int start, int pageLength, out int count);
		
	
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_ClassList_Section key.
		///		FK_ClassList_Section Description: 
		/// </summary>
		/// <param name="_sectionId">The key for the course offering’s Section to which this student has enrolled.</param>
		/// <returns>Returns a typed collection of CBRSystem.Entities.EnrolledStudent objects.</returns>
		public TList<EnrolledStudent> GetBySectionId(System.Int32 _sectionId)
		{
			int count = -1;
			return GetBySectionId(_sectionId, 0,int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_ClassList_Section key.
		///		FK_ClassList_Section Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_sectionId">The key for the course offering’s Section to which this student has enrolled.</param>
		/// <returns>Returns a typed collection of CBRSystem.Entities.EnrolledStudent objects.</returns>
		/// <remarks></remarks>
		public TList<EnrolledStudent> GetBySectionId(TransactionManager transactionManager, System.Int32 _sectionId)
		{
			int count = -1;
			return GetBySectionId(transactionManager, _sectionId, 0, int.MaxValue, out count);
		}
		
			/// <summary>
		/// 	Gets rows from the datasource based on the FK_ClassList_Section key.
		///		FK_ClassList_Section Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_sectionId">The key for the course offering’s Section to which this student has enrolled.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of CBRSystem.Entities.EnrolledStudent objects.</returns>
		public TList<EnrolledStudent> GetBySectionId(TransactionManager transactionManager, System.Int32 _sectionId, int start, int pageLength)
		{
			int count = -1;
			return GetBySectionId(transactionManager, _sectionId, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_ClassList_Section key.
		///		fkClassListSection Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_sectionId">The key for the course offering’s Section to which this student has enrolled.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of CBRSystem.Entities.EnrolledStudent objects.</returns>
		public TList<EnrolledStudent> GetBySectionId(System.Int32 _sectionId, int start, int pageLength)
		{
			int count =  -1;
			return GetBySectionId(null, _sectionId, start, pageLength,out count);	
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_ClassList_Section key.
		///		fkClassListSection Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_sectionId">The key for the course offering’s Section to which this student has enrolled.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of CBRSystem.Entities.EnrolledStudent objects.</returns>
		public TList<EnrolledStudent> GetBySectionId(System.Int32 _sectionId, int start, int pageLength,out int count)
		{
			return GetBySectionId(null, _sectionId, start, pageLength, out count);	
		}
						
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_ClassList_Section key.
		///		FK_ClassList_Section Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_sectionId">The key for the course offering’s Section to which this student has enrolled.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns a typed collection of CBRSystem.Entities.EnrolledStudent objects.</returns>
		public abstract TList<EnrolledStudent> GetBySectionId(TransactionManager transactionManager, System.Int32 _sectionId, int start, int pageLength, out int count);
		
	
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_ClassList_Student key.
		///		FK_ClassList_Student Description: 
		/// </summary>
		/// <param name="_studentId">The key for the Student who has enrolled in this section of the course offering.</param>
		/// <returns>Returns a typed collection of CBRSystem.Entities.EnrolledStudent objects.</returns>
		public TList<EnrolledStudent> GetByStudentId(System.Int32 _studentId)
		{
			int count = -1;
			return GetByStudentId(_studentId, 0,int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_ClassList_Student key.
		///		FK_ClassList_Student Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_studentId">The key for the Student who has enrolled in this section of the course offering.</param>
		/// <returns>Returns a typed collection of CBRSystem.Entities.EnrolledStudent objects.</returns>
		/// <remarks></remarks>
		public TList<EnrolledStudent> GetByStudentId(TransactionManager transactionManager, System.Int32 _studentId)
		{
			int count = -1;
			return GetByStudentId(transactionManager, _studentId, 0, int.MaxValue, out count);
		}
		
			/// <summary>
		/// 	Gets rows from the datasource based on the FK_ClassList_Student key.
		///		FK_ClassList_Student Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_studentId">The key for the Student who has enrolled in this section of the course offering.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of CBRSystem.Entities.EnrolledStudent objects.</returns>
		public TList<EnrolledStudent> GetByStudentId(TransactionManager transactionManager, System.Int32 _studentId, int start, int pageLength)
		{
			int count = -1;
			return GetByStudentId(transactionManager, _studentId, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_ClassList_Student key.
		///		fkClassListStudent Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_studentId">The key for the Student who has enrolled in this section of the course offering.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of CBRSystem.Entities.EnrolledStudent objects.</returns>
		public TList<EnrolledStudent> GetByStudentId(System.Int32 _studentId, int start, int pageLength)
		{
			int count =  -1;
			return GetByStudentId(null, _studentId, start, pageLength,out count);	
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_ClassList_Student key.
		///		fkClassListStudent Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_studentId">The key for the Student who has enrolled in this section of the course offering.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of CBRSystem.Entities.EnrolledStudent objects.</returns>
		public TList<EnrolledStudent> GetByStudentId(System.Int32 _studentId, int start, int pageLength,out int count)
		{
			return GetByStudentId(null, _studentId, start, pageLength, out count);	
		}
						
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_ClassList_Student key.
		///		FK_ClassList_Student Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_studentId">The key for the Student who has enrolled in this section of the course offering.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns a typed collection of CBRSystem.Entities.EnrolledStudent objects.</returns>
		public abstract TList<EnrolledStudent> GetByStudentId(TransactionManager transactionManager, System.Int32 _studentId, int start, int pageLength, out int count);
		
		#endregion

		#region Get By Index Functions
		
		/// <summary>
		/// 	Gets a row from the DataSource based on its primary key.
		/// </summary>
		/// <param name="transactionManager">A <see cref="TransactionManager"/> object.</param>
		/// <param name="key">The unique identifier of the row to retrieve.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <returns>Returns an instance of the Entity class.</returns>
		public override CBRSystem.Entities.EnrolledStudent Get(TransactionManager transactionManager, CBRSystem.Entities.EnrolledStudentKey key, int start, int pageLength)
		{
			return GetByEnrolledStudentId(transactionManager, key.EnrolledStudentId, start, pageLength);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the primary key PK_ClassList index.
		/// </summary>
		/// <param name="_enrolledStudentId">The primary key.</param>
		/// <returns>Returns an instance of the <see cref="CBRSystem.Entities.EnrolledStudent"/> class.</returns>
		public CBRSystem.Entities.EnrolledStudent GetByEnrolledStudentId(System.Int32 _enrolledStudentId)
		{
			int count = -1;
			return GetByEnrolledStudentId(null,_enrolledStudentId, 0, int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_ClassList index.
		/// </summary>
		/// <param name="_enrolledStudentId">The primary key.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="CBRSystem.Entities.EnrolledStudent"/> class.</returns>
		public CBRSystem.Entities.EnrolledStudent GetByEnrolledStudentId(System.Int32 _enrolledStudentId, int start, int pageLength)
		{
			int count = -1;
			return GetByEnrolledStudentId(null, _enrolledStudentId, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_ClassList index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_enrolledStudentId">The primary key.</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="CBRSystem.Entities.EnrolledStudent"/> class.</returns>
		public CBRSystem.Entities.EnrolledStudent GetByEnrolledStudentId(TransactionManager transactionManager, System.Int32 _enrolledStudentId)
		{
			int count = -1;
			return GetByEnrolledStudentId(transactionManager, _enrolledStudentId, 0, int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_ClassList index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_enrolledStudentId">The primary key.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="CBRSystem.Entities.EnrolledStudent"/> class.</returns>
		public CBRSystem.Entities.EnrolledStudent GetByEnrolledStudentId(TransactionManager transactionManager, System.Int32 _enrolledStudentId, int start, int pageLength)
		{
			int count = -1;
			return GetByEnrolledStudentId(transactionManager, _enrolledStudentId, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_ClassList index.
		/// </summary>
		/// <param name="_enrolledStudentId">The primary key.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="CBRSystem.Entities.EnrolledStudent"/> class.</returns>
		public CBRSystem.Entities.EnrolledStudent GetByEnrolledStudentId(System.Int32 _enrolledStudentId, int start, int pageLength, out int count)
		{
			return GetByEnrolledStudentId(null, _enrolledStudentId, start, pageLength, out count);
		}
		
				
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_ClassList index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_enrolledStudentId">The primary key.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns an instance of the <see cref="CBRSystem.Entities.EnrolledStudent"/> class.</returns>
		public abstract CBRSystem.Entities.EnrolledStudent GetByEnrolledStudentId(TransactionManager transactionManager, System.Int32 _enrolledStudentId, int start, int pageLength, out int count);
						
		#endregion "Get By Index Functions"
	
		#region Custom Methods
		
		
		#region EnrolledStudent_LookupBySectionNameAndCourseNumber 
		
		/// <summary>
		///	This method wrap the 'EnrolledStudent_LookupBySectionNameAndCourseNumber' stored procedure. 
		/// </summary>
		/// <param name="sectionName"> A <c>System.String</c> instance.</param>
		/// <param name="courseNumber"> A <c>System.String</c> instance.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		public void LookupBySectionNameAndCourseNumber(System.String sectionName, System.String courseNumber)
		{
			 LookupBySectionNameAndCourseNumber(null, 0, int.MaxValue , sectionName, courseNumber);
		}
		
		/// <summary>
		///	This method wrap the 'EnrolledStudent_LookupBySectionNameAndCourseNumber' stored procedure. 
		/// </summary>
		/// <param name="sectionName"> A <c>System.String</c> instance.</param>
		/// <param name="courseNumber"> A <c>System.String</c> instance.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		public void LookupBySectionNameAndCourseNumber(int start, int pageLength, System.String sectionName, System.String courseNumber)
		{
			 LookupBySectionNameAndCourseNumber(null, start, pageLength , sectionName, courseNumber);
		}
				
		/// <summary>
		///	This method wrap the 'EnrolledStudent_LookupBySectionNameAndCourseNumber' stored procedure. 
		/// </summary>
		/// <param name="sectionName"> A <c>System.String</c> instance.</param>
		/// <param name="courseNumber"> A <c>System.String</c> instance.</param>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		public void LookupBySectionNameAndCourseNumber(TransactionManager transactionManager, System.String sectionName, System.String courseNumber)
		{
			 LookupBySectionNameAndCourseNumber(transactionManager, 0, int.MaxValue , sectionName, courseNumber);
		}
		
		/// <summary>
		///	This method wrap the 'EnrolledStudent_LookupBySectionNameAndCourseNumber' stored procedure. 
		/// </summary>
		/// <param name="sectionName"> A <c>System.String</c> instance.</param>
		/// <param name="courseNumber"> A <c>System.String</c> instance.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		public abstract void LookupBySectionNameAndCourseNumber(TransactionManager transactionManager, int start, int pageLength , System.String sectionName, System.String courseNumber);
		
		#endregion
		
		#endregion

		#region Helper Functions	
		
		/// <summary>
		/// Fill a TList&lt;EnrolledStudent&gt; From a DataReader.
		/// </summary>
		/// <param name="reader">Datareader</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">number of rows.</param>
		/// <returns>a <see cref="TList&lt;EnrolledStudent&gt;"/></returns>
		public static TList<EnrolledStudent> Fill(IDataReader reader, TList<EnrolledStudent> rows, int start, int pageLength)
		{
			NetTiersProvider currentProvider = DataRepository.Provider;
            bool useEntityFactory = currentProvider.UseEntityFactory;
            bool enableEntityTracking = currentProvider.EnableEntityTracking;
            LoadPolicy currentLoadPolicy = currentProvider.CurrentLoadPolicy;
			Type entityCreationFactoryType = currentProvider.EntityCreationalFactoryType;
			
			// advance to the starting row
			for (int i = 0; i < start; i++)
			{
				if (!reader.Read())
				return rows; // not enough rows, just return
			}
			for (int i = 0; i < pageLength; i++)
			{
				if (!reader.Read())
					break; // we are done
					
				string key = null;
				
				CBRSystem.Entities.EnrolledStudent c = null;
				if (useEntityFactory)
				{
					key = new System.Text.StringBuilder("EnrolledStudent")
					.Append("|").Append((System.Int32)reader[((int)EnrolledStudentColumn.EnrolledStudentId - 1)]).ToString();
					c = EntityManager.LocateOrCreate<EnrolledStudent>(
					key.ToString(), // EntityTrackingKey
					"EnrolledStudent",  //Creational Type
					entityCreationFactoryType,  //Factory used to create entity
					enableEntityTracking); // Track this entity?
				}
				else
				{
					c = new CBRSystem.Entities.EnrolledStudent();
				}
				
				if (!enableEntityTracking ||
					c.EntityState == EntityState.Added ||
					(enableEntityTracking &&
					
						(
							(currentLoadPolicy == LoadPolicy.PreserveChanges && c.EntityState == EntityState.Unchanged) ||
							(currentLoadPolicy == LoadPolicy.DiscardChanges && c.EntityState != EntityState.Unchanged)
						)
					))
				{
					c.SuppressEntityEvents = true;
					c.EnrolledStudentId = (System.Int32)reader[((int)EnrolledStudentColumn.EnrolledStudentId - 1)];
					c.StudentId = (System.Int32)reader[((int)EnrolledStudentColumn.StudentId - 1)];
					c.CurrentStatus = (System.Int32)reader[((int)EnrolledStudentColumn.CurrentStatus - 1)];
					c.SectionId = (System.Int32)reader[((int)EnrolledStudentColumn.SectionId - 1)];
					c.FinalMarkAwarded = (reader.IsDBNull(((int)EnrolledStudentColumn.FinalMarkAwarded - 1)))?null:(System.Byte?)reader[((int)EnrolledStudentColumn.FinalMarkAwarded - 1)];
					c.EntityTrackingKey = key;
					c.AcceptChanges();
					c.SuppressEntityEvents = false;
				}
				rows.Add(c);
			}
		return rows;
		}		
		/// <summary>
		/// Refreshes the <see cref="CBRSystem.Entities.EnrolledStudent"/> object from the <see cref="IDataReader"/>.
		/// </summary>
		/// <param name="reader">The <see cref="IDataReader"/> to read from.</param>
		/// <param name="entity">The <see cref="CBRSystem.Entities.EnrolledStudent"/> object to refresh.</param>
		public static void RefreshEntity(IDataReader reader, CBRSystem.Entities.EnrolledStudent entity)
		{
			if (!reader.Read()) return;
			
			entity.EnrolledStudentId = (System.Int32)reader[((int)EnrolledStudentColumn.EnrolledStudentId - 1)];
			entity.StudentId = (System.Int32)reader[((int)EnrolledStudentColumn.StudentId - 1)];
			entity.CurrentStatus = (System.Int32)reader[((int)EnrolledStudentColumn.CurrentStatus - 1)];
			entity.SectionId = (System.Int32)reader[((int)EnrolledStudentColumn.SectionId - 1)];
			entity.FinalMarkAwarded = (reader.IsDBNull(((int)EnrolledStudentColumn.FinalMarkAwarded - 1)))?null:(System.Byte?)reader[((int)EnrolledStudentColumn.FinalMarkAwarded - 1)];
			entity.AcceptChanges();
		}
		
		/// <summary>
		/// Refreshes the <see cref="CBRSystem.Entities.EnrolledStudent"/> object from the <see cref="DataSet"/>.
		/// </summary>
		/// <param name="dataSet">The <see cref="DataSet"/> to read from.</param>
		/// <param name="entity">The <see cref="CBRSystem.Entities.EnrolledStudent"/> object.</param>
		public static void RefreshEntity(DataSet dataSet, CBRSystem.Entities.EnrolledStudent entity)
		{
			DataRow dataRow = dataSet.Tables[0].Rows[0];
			
			entity.EnrolledStudentId = (System.Int32)dataRow["EnrolledStudentID"];
			entity.StudentId = (System.Int32)dataRow["StudentID"];
			entity.CurrentStatus = (System.Int32)dataRow["CurrentStatus"];
			entity.SectionId = (System.Int32)dataRow["SectionID"];
			entity.FinalMarkAwarded = Convert.IsDBNull(dataRow["FinalMarkAwarded"]) ? null : (System.Byte?)dataRow["FinalMarkAwarded"];
			entity.AcceptChanges();
		}
		#endregion 
		
		#region DeepLoad Methods
		/// <summary>
		/// Deep Loads the <see cref="IEntity"/> object with criteria based of the child 
		/// property collections only N Levels Deep based on the <see cref="DeepLoadType"/>.
		/// </summary>
		/// <remarks>
		/// Use this method with caution as it is possible to DeepLoad with Recursion and traverse an entire object graph.
		/// </remarks>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="entity">The <see cref="CBRSystem.Entities.EnrolledStudent"/> object to load.</param>
		/// <param name="deep">Boolean. A flag that indicates whether to recursively save all Property Collection that are descendants of this instance. If True, saves the complete object graph below this object. If False, saves this object only. </param>
		/// <param name="deepLoadType">DeepLoadType Enumeration to Include/Exclude object property collections from Load.</param>
		/// <param name="childTypes">CBRSystem.Entities.EnrolledStudent Property Collection Type Array To Include or Exclude from Load</param>
		/// <param name="innerList">A collection of child types for easy access.</param>
	    /// <exception cref="ArgumentNullException">entity or childTypes is null.</exception>
	    /// <exception cref="ArgumentException">deepLoadType has invalid value.</exception>
		public override void DeepLoad(TransactionManager transactionManager, CBRSystem.Entities.EnrolledStudent entity, bool deep, DeepLoadType deepLoadType, System.Type[] childTypes, DeepSession innerList)
		{
			if(entity == null)
				return;

			#region CurrentStatusSource	
			if (CanDeepLoad(entity, "EnrollmentStatus|CurrentStatusSource", deepLoadType, innerList) 
				&& entity.CurrentStatusSource == null)
			{
				object[] pkItems = new object[1];
				pkItems[0] = entity.CurrentStatus;
				EnrollmentStatus tmpEntity = EntityManager.LocateEntity<EnrollmentStatus>(EntityLocator.ConstructKeyFromPkItems(typeof(EnrollmentStatus), pkItems), DataRepository.Provider.EnableEntityTracking);
				if (tmpEntity != null)
					entity.CurrentStatusSource = tmpEntity;
				else
					entity.CurrentStatusSource = DataRepository.EnrollmentStatusProvider.GetByEnrollmentStatusId(transactionManager, entity.CurrentStatus);		
				
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'CurrentStatusSource' loaded. key " + entity.EntityTrackingKey);
				#endif 
				
				if (deep && entity.CurrentStatusSource != null)
				{
					innerList.SkipChildren = true;
					DataRepository.EnrollmentStatusProvider.DeepLoad(transactionManager, entity.CurrentStatusSource, deep, deepLoadType, childTypes, innerList);
					innerList.SkipChildren = false;
				}
					
			}
			#endregion CurrentStatusSource

			#region SectionIdSource	
			if (CanDeepLoad(entity, "Section|SectionIdSource", deepLoadType, innerList) 
				&& entity.SectionIdSource == null)
			{
				object[] pkItems = new object[1];
				pkItems[0] = entity.SectionId;
				Section tmpEntity = EntityManager.LocateEntity<Section>(EntityLocator.ConstructKeyFromPkItems(typeof(Section), pkItems), DataRepository.Provider.EnableEntityTracking);
				if (tmpEntity != null)
					entity.SectionIdSource = tmpEntity;
				else
					entity.SectionIdSource = DataRepository.SectionProvider.GetBySectionId(transactionManager, entity.SectionId);		
				
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'SectionIdSource' loaded. key " + entity.EntityTrackingKey);
				#endif 
				
				if (deep && entity.SectionIdSource != null)
				{
					innerList.SkipChildren = true;
					DataRepository.SectionProvider.DeepLoad(transactionManager, entity.SectionIdSource, deep, deepLoadType, childTypes, innerList);
					innerList.SkipChildren = false;
				}
					
			}
			#endregion SectionIdSource

			#region StudentIdSource	
			if (CanDeepLoad(entity, "Student|StudentIdSource", deepLoadType, innerList) 
				&& entity.StudentIdSource == null)
			{
				object[] pkItems = new object[1];
				pkItems[0] = entity.StudentId;
				Student tmpEntity = EntityManager.LocateEntity<Student>(EntityLocator.ConstructKeyFromPkItems(typeof(Student), pkItems), DataRepository.Provider.EnableEntityTracking);
				if (tmpEntity != null)
					entity.StudentIdSource = tmpEntity;
				else
					entity.StudentIdSource = DataRepository.StudentProvider.GetByStudentId(transactionManager, entity.StudentId);		
				
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'StudentIdSource' loaded. key " + entity.EntityTrackingKey);
				#endif 
				
				if (deep && entity.StudentIdSource != null)
				{
					innerList.SkipChildren = true;
					DataRepository.StudentProvider.DeepLoad(transactionManager, entity.StudentIdSource, deep, deepLoadType, childTypes, innerList);
					innerList.SkipChildren = false;
				}
					
			}
			#endregion StudentIdSource
			
			//used to hold DeepLoad method delegates and fire after all the local children have been loaded.
			Dictionary<string, KeyValuePair<Delegate, object>> deepHandles = new Dictionary<string, KeyValuePair<Delegate, object>>();
			
			//Fire all DeepLoad Items
			foreach(KeyValuePair<Delegate, object> pair in deepHandles.Values)
		    {
                pair.Key.DynamicInvoke((object[])pair.Value);
		    }
			deepHandles = null;
		}
		
		#endregion 
		
		#region DeepSave Methods

		/// <summary>
		/// Deep Save the entire object graph of the CBRSystem.Entities.EnrolledStudent object with criteria based of the child 
		/// Type property array and DeepSaveType.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="entity">CBRSystem.Entities.EnrolledStudent instance</param>
		/// <param name="deepSaveType">DeepSaveType Enumeration to Include/Exclude object property collections from Save.</param>
		/// <param name="childTypes">CBRSystem.Entities.EnrolledStudent Property Collection Type Array To Include or Exclude from Save</param>
		/// <param name="innerList">A Hashtable of child types for easy access.</param>
		public override bool DeepSave(TransactionManager transactionManager, CBRSystem.Entities.EnrolledStudent entity, DeepSaveType deepSaveType, System.Type[] childTypes, DeepSession innerList)
		{	
			if (entity == null)
				return false;
							
			#region Composite Parent Properties
			//Save Source Composite Properties, however, don't call deep save on them.  
			//So they only get saved a single level deep.
			
			#region CurrentStatusSource
			if (CanDeepSave(entity, "EnrollmentStatus|CurrentStatusSource", deepSaveType, innerList) 
				&& entity.CurrentStatusSource != null)
			{
				DataRepository.EnrollmentStatusProvider.Save(transactionManager, entity.CurrentStatusSource);
				entity.CurrentStatus = entity.CurrentStatusSource.EnrollmentStatusId;
			}
			#endregion 
			
			#region SectionIdSource
			if (CanDeepSave(entity, "Section|SectionIdSource", deepSaveType, innerList) 
				&& entity.SectionIdSource != null)
			{
				DataRepository.SectionProvider.Save(transactionManager, entity.SectionIdSource);
				entity.SectionId = entity.SectionIdSource.SectionId;
			}
			#endregion 
			
			#region StudentIdSource
			if (CanDeepSave(entity, "Student|StudentIdSource", deepSaveType, innerList) 
				&& entity.StudentIdSource != null)
			{
				DataRepository.StudentProvider.Save(transactionManager, entity.StudentIdSource);
				entity.StudentId = entity.StudentIdSource.StudentId;
			}
			#endregion 
			#endregion Composite Parent Properties

			// Save Root Entity through Provider
			if (!entity.IsDeleted)
				this.Save(transactionManager, entity);
			
			//used to hold DeepSave method delegates and fire after all the local children have been saved.
			Dictionary<string, KeyValuePair<Delegate, object>> deepHandles = new Dictionary<string, KeyValuePair<Delegate, object>>();
			//Fire all DeepSave Items
			foreach(KeyValuePair<Delegate, object> pair in deepHandles.Values)
		    {
                pair.Key.DynamicInvoke((object[])pair.Value);
		    }
			
			// Save Root Entity through Provider, if not already saved in delete mode
			if (entity.IsDeleted)
				this.Save(transactionManager, entity);
				

			deepHandles = null;
						
			return true;
		}
		#endregion
	} // end class
	
	#region EnrolledStudentChildEntityTypes
	
	///<summary>
	/// Enumeration used to expose the different child entity types 
	/// for child properties in <c>CBRSystem.Entities.EnrolledStudent</c>
	///</summary>
	public enum EnrolledStudentChildEntityTypes
	{
		
		///<summary>
		/// Composite Property for <c>EnrollmentStatus</c> at CurrentStatusSource
		///</summary>
		[ChildEntityType(typeof(EnrollmentStatus))]
		EnrollmentStatus,
			
		///<summary>
		/// Composite Property for <c>Section</c> at SectionIdSource
		///</summary>
		[ChildEntityType(typeof(Section))]
		Section,
			
		///<summary>
		/// Composite Property for <c>Student</c> at StudentIdSource
		///</summary>
		[ChildEntityType(typeof(Student))]
		Student,
		}
	
	#endregion EnrolledStudentChildEntityTypes
	
	#region EnrolledStudentFilterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="SqlFilterBuilder&lt;EnrolledStudentColumn&gt;"/> class
	/// that is used exclusively with a <see cref="EnrolledStudent"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class EnrolledStudentFilterBuilder : SqlFilterBuilder<EnrolledStudentColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the EnrolledStudentFilterBuilder class.
		/// </summary>
		public EnrolledStudentFilterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the EnrolledStudentFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public EnrolledStudentFilterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the EnrolledStudentFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public EnrolledStudentFilterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion EnrolledStudentFilterBuilder
	
	#region EnrolledStudentParameterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="ParameterizedSqlFilterBuilder&lt;EnrolledStudentColumn&gt;"/> class
	/// that is used exclusively with a <see cref="EnrolledStudent"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class EnrolledStudentParameterBuilder : ParameterizedSqlFilterBuilder<EnrolledStudentColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the EnrolledStudentParameterBuilder class.
		/// </summary>
		public EnrolledStudentParameterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the EnrolledStudentParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public EnrolledStudentParameterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the EnrolledStudentParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public EnrolledStudentParameterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion EnrolledStudentParameterBuilder
	
	#region EnrolledStudentSortBuilder
    
    /// <summary>
    /// A strongly-typed instance of the <see cref="SqlSortBuilder&lt;EnrolledStudentColumn&gt;"/> class
	/// that is used exclusively with a <see cref="EnrolledStudent"/> object.
    /// </summary>
    [CLSCompliant(true)]
    public class EnrolledStudentSortBuilder : SqlSortBuilder<EnrolledStudentColumn>
    {
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the EnrolledStudentSqlSortBuilder class.
		/// </summary>
		public EnrolledStudentSortBuilder() : base() { }

		#endregion Constructors

    }    
    #endregion EnrolledStudentSortBuilder
	
} // end namespace
